const api = require("../../../api/sop");
import { log, err, to } from "../../../utils/wxapi";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    option1: [
      { text: "价格", value: "" },
      { text: "由高到低", value: "PRICE_HIGH_TO_DOWN" },
      { text: "由低到高", value: "PRICE_DOWN_TO_HIGH" },
    ],
    option2: [
      { text: "发布时间", value: "" },
      { text: "由近到远", value: "DATE_NEAR_TO_FAR" },
      { text: "由远到进", value: "DATE_FAR_TO_NEAR" },
    ],
    value1: "",
    value2: "",
    // 列表数据
    jobLists: [],
    reqCode: "",
    page: 1,
    size: 20,
    state: 1,
    city: "",
  },
  onLoad(e) {
    if (e) {
      const { state } = e;
      this.setData({ state });
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({ city: wx.getStorageSync("city") || "鹤壁" });
    this.postSeach();
  },
  // 岗位列表
  async postSeach() {
    try {
      const { page, size, reqCode, state, city } = this.data;
      const data = {
        page,
        size,
        reqCode,
        data: JSON.stringify({ state, interviewAddress: city }),
      };
      const res = await api.work_list(data);
      if (res.respCode === 200) {
        let Arrays = JSON.parse(res.source);
        console.log(Arrays);
        this.setData({ jobLists: Arrays });
      }
    } catch (error) {
      err(error);
      throw error;
    }
  },
  change1(e) {
    const value1 = e.detail;
    this.setData({ value1, value2: "", reqCode: value1 });
    this.postSeach();
  },
  change2(e) {
    const value2 = e.detail;
    this.setData({ value2, value1: "", reqCode: value2 });
    this.postSeach();
  },
  goToContent(e) {
    const { id } = e.currentTarget.dataset;
    to("/two/pages/detail/detail?id=" + id);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
